package com.itheima;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;


public class MapDemo {
    public static void main(String[] args){
//        text0();
        //text1();
        //test2();
        test3();

    }
    public static void test3(){
        Map<String,Double> map = new HashMap<>();
        map.put("张三",90.0);
        map.put("李四",80.0);
        map.put("王五",70.0);
        map.put("赵六",60.0);
        map.forEach((key, value) -> System.out.println(key + "---" + value));
    }
    public static void test2(){
        Map<String,Double> map = new HashMap<>();
        map.put("张三",90.0);
        map.put("李四",80.0);
        map.put("王五",70.0);
        map.put("赵六",60.0);
        //1.将map集合转成sey集合（将map中的key-value绑定成一个对象entry）
        Set<Map.Entry<String,Double>> entrySet =map.entrySet();
        //2.遍历set集合
        for (Map.Entry<String,Double> entry:entrySet){
            //3.根据entry获取value和key
            String Key = entry.getKey();
            Double value = entry.getValue();
            System.out.println(Key+"----"+value);
        }
    }


    public static void text1() {
        Map<String,Double> map = new HashMap<>();
        map.put("张三",90.0);
        map.put("李四",80.0);
        map.put("王五",70.0);
        map.put("赵六",60.0);
        //将map中的所有键值取出来放到set集合中
        Set<String> KeySet = map.keySet();
        for (String Key:KeySet){
            Double value = map.get(Key);
            System.out.println(Key+"-----"+value);
        }
    }

    private static void text0() {
        Map<String,Double> map = new HashMap<>();
        map.put("张三",90.0);
        map.put("李四",80.0);
        map.put("王五",70.0);
        map.put("赵六",60.0);
        map.put("赵六",100.0);
        System.out.println(map);

        map.remove("张三");
        System.out.println(map);
//        map.clear();
//        System.out.println(map);
        boolean b1 = map.containsKey("李四");
        System.out.println("b1 = "+ b1);
        boolean b2 = map.containsValue(80.0);
        System.out.println("b2 = "+ b2);

        boolean empty = map.isEmpty();
        System.out.println("empty = "+ empty);
        int size = map.size();
        System.out.println("size = "+ size);
    }
}
